﻿using System;

namespace ConsoleDemo.InterfaceSegregation
{
    //例子：背景是 Driver（小女生）撞车了，小男生安慰她以后可以开 Tank 上班。
    //如何让 Driver 能够既能开 Tank 又能开 Car

    internal class InterfaceDemo
    {
        public static void Call()
        {
            var driver = new Driver(new HeavyTank());
            driver.Drive();
        }
    }
    class Driver
    {
        private IVehicle _vehicle;

        public Driver(IVehicle vehicle)
        {
            _vehicle = vehicle;
        }

        public void Drive()
        {
            _vehicle.Run();
        }
    }

    interface IVehicle
    {
        void Run();
    }

    class Car : IVehicle
    {
        public void Run()
        {
            Console.WriteLine("Car is running ...");
        }
    }

    class Truck : IVehicle
    {
        public void Run()
        {
            Console.WriteLine("Truck is running ...");
        }
    }

    interface ITank
    {
        void Fire();
    }

    class LightTank : ITank, IVehicle
    {
        public void Fire()
        {
            Console.WriteLine("Boom!");
        }

        public void Run()
        {
            Console.WriteLine("Ka ka ka ...");
        }
    }

    class MediumTank : ITank, IVehicle
    {
        public void Fire()
        {
            Console.WriteLine("Boom!!");
        }

        public void Run()
        {
            Console.WriteLine("Ka! ka! ka! ...");
        }
    }

    class HeavyTank : ITank, IVehicle
    {
        public void Fire()
        {
            Console.WriteLine("Boom!!!");
        }

        public void Run()
        {
            Console.WriteLine("Ka!! ka!! ka!! ...");
        }
    }
}
